package com.shopowner.service.impl;



import com.shopowner.dao.ShopownerDao;
import com.shopowner.dto.DTO;
import com.shopowner.dto.MessageEnum;
import com.shopowner.page.PageInfo;
import com.shopowner.entity.Shopowner;
import com.shopowner.service.ShopownerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("shopownerService")
public class ShopownerServiceImpl implements ShopownerService {
    @Resource
    ShopownerDao shopownerDao;
    @Override
    public DTO<Shopowner> getAllShopowners()  throws Exception{
        List<Shopowner> shopowners = shopownerDao.getAllShopowners();
        MessageEnum messageEnum  = Optional.ofNullable(shopowners).isPresent()?MessageEnum.GETADMINSUCCESS: MessageEnum.GETADMINFAIL;
        return new DTO<Shopowner>(messageEnum.getCode(),messageEnum.getMessage(),shopowners);
    }

    @Override
    public DTO<Shopowner> deleteShopownerBySno(String sno)  throws Exception{
        Integer result = shopownerDao.deleteShopownerBySno(sno);
        MessageEnum messageEnum  =result> 0?MessageEnum.DELETEADMINSUCCESS:MessageEnum.DELETEADMINFAIL;
        return new DTO<Shopowner>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Shopowner> selectShopownerBySno(String sno)  throws Exception{
        Shopowner shopowners = shopownerDao.selectShopownerBySno(sno);
        MessageEnum messageEnum  = Optional.ofNullable(shopowners).isPresent()?MessageEnum.GETPARENTSSUCCESS: MessageEnum.GETPARENTSFAIL;
        return new DTO<Shopowner>(messageEnum.getCode(),messageEnum.getMessage(),shopowners);
    }
    @Override
    public DTO<Shopowner> updateShopownerBySno(Shopowner shopowner)  throws Exception{
        Integer result = shopownerDao.updateShopownerBySno(shopowner);
        MessageEnum messageEnum  =result> 0?MessageEnum.UPDATEADMINSUCCESS:MessageEnum.UPDATEADMINFAIL;
        return new DTO<Shopowner>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Shopowner> addShopowner(Shopowner shopowner) throws Exception {
        Integer result = shopownerDao.addShopowner(shopowner);
        MessageEnum messageEnum  = result> 0?MessageEnum.ADDADMINSUCCESS:MessageEnum.ADDADMINFAIL;
        return new DTO<Shopowner>(messageEnum.getCode(),messageEnum.getMessage());
    }
    @Override
    public DTO<Shopowner> getShopownerByPage(PageInfo pageInfo ) throws Exception {
        List<Shopowner> shopowners = shopownerDao.getShopownerByPage(pageInfo);
        MessageEnum messageEnum  = Optional.ofNullable(shopowners).isPresent()?MessageEnum.GETADMINSUCCESS: MessageEnum.GETADMINFAIL;
        return new DTO<Shopowner>(messageEnum.getCode(),messageEnum.getMessage(),shopowners,pageInfo);
    }


}
